import {createRouter, createWebHashHistory} from 'vue-router' // 改用 hash 模式

const routes = [
    {
        path: '/',
        name: 'Login',
        component: () => import('@/view/login.vue')
    },
    {
        path: '/index',
        name: 'Index',
        component: () => import('@/view/index.vue')
    },
    {
        path: '/run-status',
        name: 'RunStatus',
        component: () => import('@/view/run_status/index.vue')
    },
    {
        path: '/mes-log',
        name: 'MesLog',
        component: () => import('@/view/mes_log/index.vue')
    },
    {
        path: '/mes-log/detail/:id',
        name: 'MesLogDetail',
        component: () => import('@/view/mes_log/mes_log_detail/index.vue'),
        props: true
    },
    {
        path: '/alarm-log',
        name: 'AlarmLog',
        component: () => import('@/view/alarm_log/index.vue')
    },
    {
        path: '/chart',
        name: 'Chart',
        component: () => import('@/view/chart/index.vue')
    },

    {
        path: '/settings-nav',
        name: 'SettingsNavPage',
        component: () => import('@/view/settings_nav/index.vue')
    },
    {
        path: '/settings/plc-config',
        name: 'PlcConfig',
        component: () => import('@/view/settings_nav/plc_config/index.vue')
    },
    {
        path: '/settings/plc-config/flowchart/:template?',
        name: 'PlcConfigFlowchart',
        component: () => import('@/view/settings_nav/plc_config/flowchart_viewer/index.vue')
    },
    {
        path: '/settings/event-config',
        name: 'EventConfigNav',
        component: () => import('@/view/settings_nav/event_config_nav/index.vue')
    },
    {
        path: '/settings/event-config-nav/print_sn',
        name: 'EventConfigPrintSN',
        component: () => import('@/view/settings_nav/event_config_nav/print_sn/index.vue')
    },
    {
        path: '/settings/event-config-nav/sn_check_in',
        name: 'EventConfigSNCheckIn',
        component: () => import('@/view/settings_nav/event_config_nav/sn_check_in/index.vue')
    },
    {
        path: '/settings/event-config-nav/sn_check_out',
        name: 'EventConfigSNCheckout',
        component: () => import('@/view/settings_nav/event_config_nav/sn_check_out/index.vue')
    },
    {
        path: '/settings/event-config-nav/link_comp',
        name: 'EventConfigLinkComp',
        component: () => import('@/view/settings_nav/event_config_nav/link_comp/index.vue')
    },
    {
        path: '/settings/event-config-nav/status',
        name: 'EventConfigStatus',
        component: () => import('@/view/settings_nav/event_config_nav/status/index.vue')
    },
    {
        path: '/settings/event-config-nav/alarm',
        name: 'EventConfigAlarm',
        component: () => import('@/view/settings_nav/event_config_nav/alarm/index.vue')
    },
    {
        path: '/settings/alarm-config',
        name: 'AlarmConfig',
        component: () => import('@/view/settings_nav/alarm_config/index.vue')
    },
    {
        path: '/settings/alarm-config/edit/:id?',
        name: 'AlarmConfigEditAdd',
        component: () => import('@/view/settings_nav/alarm_config/edit_add/index.vue')
    },
    {
        path: '/settings/alarm-config/delete/:id',
        name: 'AlarmConfigDeleteConfirm',
        component: () => import('@/view/settings_nav/alarm_config/delete_confirm/index.vue')
    },
    {
        path: '/settings/plc-address-config',
        name: 'PLCAddressConfig',
        component: () => import('@/view/settings_nav/plc_address_config/index.vue'),
        meta: {
            title: 'PLC地址配置',
            requiresAuth: true
        }
    },
    {
        path: '/settings/plc-address-config/add',
        name: 'PLCAddressConfigAdd',
        component: () => import('@/view/settings_nav/plc_address_config/add/index.vue'),
        meta: {
            title: '添加PLC地址',
            requiresAuth: true
        }
    },
    {
        path: '/settings/plc-address-config/edit/:id',
        name: 'PLCAddressConfigEdit',
        component: () => import('@/view/settings_nav/plc_address_config/edit/index.vue'),
        meta: {
            title: '编辑PLC地址',
            requiresAuth: true
        }
    },
    {
        path: '/settings/plc-address-config/delete/:id',
        name: 'PLCAddressConfigDeleteConfirm',
        component: () => import('@/view/settings_nav/plc_address_config/delete_confirm/index.vue')
    },
    {
        path: '/settings/user-management',
        name: 'UserManagementList',
        component: () => import('@/view/settings_nav/user_management_list/index.vue')
    },
    {
        path: '/settings/user-management/edit/:id?',
        name: 'UserEditAdd',
        component: () => import('@/view/settings_nav/user_management_list/edit_add/index.vue')
    },
    {
        path: '/settings/user-management/delete/:id',
        name: 'UserDeleteConfirm',
        component: () => import('@/view/settings_nav/user_management_list/delete_confirm/index.vue')
    },
    {
        path: '/flow-diagrams',
        name: 'FlowDiagrams',
        component: () => import('@/view/flow_diagrams/index.vue')
    },
    {
        path: '/flow-diagrams/:id',
        name: 'FlowDiagramDetail',
        component: () => import('@/view/flow_diagrams/detail.vue')
    },
    {
        path: '/mes-mock',
        name: 'MesMock',
        component: ()=> import('@/view/mes_mock/index.vue'),
        meta: {
            title: 'MES模拟服务器'
        }
    }
]

const router = createRouter({
    history: createWebHashHistory(), // 改用 hash 模式
    routes
})

// 路由守卫
// router.beforeEach((to, from, next) => {
//
//     if (to.meta.requiresAuth) {
//         const loggedInUser = sessionStorage.getItem('loggedInUser')
//         if (!loggedInUser) {
//             next('/')
//             return
//         }
//     }
//     next()
// })

export default router
